package com.travelsmart.client.apresentacao.model;

import java.util.List;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.travelsmart.client.apresentacao.controller.Observable;

import com.travelsmart.client.apresentacao.model.SmartHotelModel.LOAD_STATUS;

import com.travelsmart.client.bean.to.ReservaHotelTO;
import com.travelsmart.client.control.HotelSmartServiceAsync;

public class ListaReservaModel extends Observable<List<ReservaHotelTO>> {
	List<ReservaHotelTO> reservas = null;
	/*/# INICIO - EXERC. 1
	
	//FIM - EXERC. 1 #*/
	
	public void  obterReservas( Integer pagina ){
		SmartHotelModel.instance.getLoadModel().setLoad(LOAD_STATUS.LOADING);
		HotelSmartServiceAsync.service.listReservas(pagina * 4,4, 
				new AsyncCallback<List<ReservaHotelTO>>() {
			
					public void onFailure(Throwable caught){
						SmartHotelModel.instance.getErroHotelModel().setErro(caught);
						SmartHotelModel.instance.getLoadModel().setLoad(LOAD_STATUS.DONE);
					}
			
					public void onSuccess(List<ReservaHotelTO> reservas){
						setReservas(reservas);
						SmartHotelModel.instance.getLoadModel().setLoad(LOAD_STATUS.DONE);
						
					}
				});
		
	}

	public void setReservas(List<ReservaHotelTO> reservas) {
		this.reservas = reservas;
		super.setChanged();
		super.notifyObservers(reservas);
	}

}
